import os
import time
import random
from DrissionPage import ChromiumPage
import csv
import pandas as pd
import requests
import re

headers = {
        "User-Agent": "Mozilla/5.0 (-----------------------------------------------537.36"
    }

page = ChromiumPage()

home_page = 'https://www.xiaohongshu.com/explore'
test_page = 'https://www.xiaohongshu.com/explore/6694fa9d0000000025005fce?xsec_token=ABDJRnr9guYenlLIyQouS1_MxkliFGoZFwfTph7xhOKWo=&xsec_source=pc_user'

# page.get(home_page)
# input('请输入任意键继续')
page.get(test_page)

vedio_url = page.ele('xpath://head//meta[@name="og:video"]/@content').attrs['content']

response = requests.get(vedio_url, headers=headers)

if response.status_code == 200:
    with open('./vedio/video2.mp4', 'wb') as f:
        for chunk in response.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)

